﻿using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using Red.Controls.Depot.ViewModels;
using Red.Controls.Utils;

namespace Red.Controls.Depot.Converters
{
    class RevisionInfoColorConverter : IValueConverter
    {
        #region IValueConverter implementation

        public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
            var fileViewItem = value as FileViewItem;
            if ( fileViewItem == null )
                return value;

            SolidColorBrush brush;

            if ( fileViewItem.IsOutOfDate )
            {
                brush = new SolidColorBrush( Colors.Orange );
                brush.Freeze();
                return brush;
            }

            switch ( fileViewItem.P4FileState )
            {
                case P4FileState.P4FS_MarkedForAdd:
                    brush = new SolidColorBrush( Colors.Red );
                    brush.Freeze();
                    return brush;
                case P4FileState.P4FS_NotInDepot:
                    return Application.Current.Resources[ "BlackBrush" ];
                default:
                    brush = new SolidColorBrush( Colors.Green );
                    brush.Freeze();
                    return brush;
            } 
        }

        public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
            throw new NotImplementedException();
        }

        #endregion IValueConverter implementation
    }
}
